//
//  GoodsDetailBottomView.m
//  BonweBuy
//
//  Created by liuxin on 2020/2/25.
//  Copyright © 2020 liuxin. All rights reserved.
//

#import "GoodsDetailBottomView.h"

@implementation GoodsDetailBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    //添加容器视图
    UIView *containView = [UIView new];
    [self addSubview:containView];
    [containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-TABBAR_MAX_Y);
    }];
    
    //首页按钮
    GoodsDetailBottomViewButton *homePageButton = [GoodsDetailBottomViewButton new];
    [homePageButton setTitle:@"首页" forState:UIControlStateNormal];
    [homePageButton setImage:[UIImage imageWithColor:[UIColor redColor]] forState:UIControlStateNormal];
    [containView addSubview:homePageButton];
    [homePageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(kAppWidth_Mini(130));
    }];
    
    //客服按钮
    GoodsDetailBottomViewButton *serviceButton = [GoodsDetailBottomViewButton new];
    [serviceButton setTitle:@"客服" forState:UIControlStateNormal];
    [serviceButton setImage:[UIImage imageWithColor:[UIColor redColor]] forState:UIControlStateNormal];
    [containView addSubview:serviceButton];
    [serviceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(homePageButton.mas_right).offset(-1);
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(kAppWidth_Mini(130));
    }];
    
    //购物车按钮
    GoodsDetailBottomViewButton *shopCarButton = [GoodsDetailBottomViewButton new];
    [shopCarButton setTitle:@"购物车" forState:UIControlStateNormal];
    [shopCarButton setImage:[UIImage imageWithColor:[UIColor redColor]] forState:UIControlStateNormal];
    [containView addSubview:shopCarButton];
    [shopCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(serviceButton.mas_right).offset(-1);
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(kAppWidth_Mini(130));
    }];
    
    //立即购买
    UIButton *buyButton = [UIButton initWithTitleStr:@"立即购买" titleColor:[UIColor orangeColor] withFont:UIPFRegularFont(15)];
    [containView addSubview:buyButton];
    [buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopCarButton.mas_right);
        make.top.bottom.mas_equalTo(0);
    }];
    
    
    //添加至购物车
    UIButton *addShopCarButton = [UIButton initWithTitleStr:@"添加至购物车" titleColor:[UIColor whiteColor] withFont:UIPFRegularFont(15) bgColor:[UIColor orangeColor]];
    [containView addSubview:addShopCarButton];
    [addShopCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(buyButton.mas_right);
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.width.equalTo(buyButton.mas_width);
    }];
    
    //添加一条分割线
    [self addLineWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1) color:[UIColor grayColor]];
    
}

@end


@implementation GoodsDetailBottomViewButton

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self initTheSubViews];
    }
    return  self;
}

-(void)initTheSubViews{
    [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.titleLabel.font = UIPFRegularFont(12);
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.adjustsImageWhenHighlighted = NO;
    self.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.layer.borderWidth = 1;
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    return CGRectMake((contentRect.size.width - kAppWidth_Mini(50))/2.0,kAppWidth_Mini(20), kAppWidth_Mini(50), kAppWidth_Mini(50));
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0, kAppWidth_Mini(80), contentRect.size.width, kAppWidth_Mini(30));
}

@end
